package com.wuyangnju.healthclub.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.wuyangnju.healthclub.service.ActivityService;
import com.wuyangnju.healthclub.service.FamilyService;
import com.wuyangnju.healthclub.service.SingleService;

@Controller
public class ActivityController {

	@Resource
	SingleService singleService;

	@Resource
	FamilyService familyService;

	@Resource
	ActivityService activityService;

	@RequestMapping(value = { "/resource/activities.get" })
	public ModelAndView get() {
		return new ModelAndView("activity", "activities", activityService.get());
	}

	@RequestMapping(value = { "/resource/activities.post" })
	public ModelAndView post(@RequestParam String cardId,
			@RequestParam String type, @RequestParam String description) {

		boolean success = activityService.post(cardId, type, description);

		if (success) {
			return new ModelAndView(new RedirectView(
					"/resource/activities.get", true));
		} else if ("single".equals(type)) {
			return new ModelAndView(new RedirectView("/resource/singles.get",
					true));
		} else {
			return new ModelAndView(new RedirectView("/resource/families.get",
					true));
		}
	}

}
